<?php
namespace Home\Controller;

use Common\Controller\HomeController;
use Common\Model\RestModel;

class VoiceController extends HomeController
{
    public function index()
    {
        $data = I('post.');
        $mess_number = M('VoiceNumber')->where(array('user_id'=>session('id')))->find();
        if(!$mess_number || count($data['ids']) > ($mess_number['capacity']-$mess_number['used'])){
            $this->error('语音可用量不足');
        }
        $take_list = M("Take")->where(array('id'=>array('in',$data['ids'])))->select();
        $rest = new RestModel();
        foreach($take_list as $key => $value){
            $rest->landingCall($value['phone'],'a.wav');
        }
        M('VoiceNumber')->where(array('user_id'=>session('id')))->setInc('used',count($data['ids']));
        M('Take')->where(array('id'=>array('in',$data['ids'])))->save(array('voice_status'=>2));
        foreach($take_list as $key => $value){
            M('VoiceRecord')->add(array('take_id'=>$value['id'],'no'=>$value['no'],'phone'=>$value['phone'],'user_id'=>session('id')));
        }
        $this->success('已加入到发送队列');
    }

}